class Stack {
    constructor () {
        this.items = []
    }
    push (element) {
        this.items.push(element)
    }
    pop () {
        return this.items.pop()
    }
    isEmpty () {
        return this.items.length === 0
    }
    // 查看栈顶元素(返回数组末尾最后一项元素)
    peek () {
        return this.items[this.items.length - 1]
    }
}
/**
 * 
 * @param {*} decNumber 需要进制转换的数据
 * @returns 
 */
function decimalToBinary (decNumber) {
    const stack = new Stack()
    let num = decNumber
    let rem
    let result = ''
    while (num > 0) {
        rem = Math.floor(num % 2) // 向下取整
        stack.push(rem)
        num = Math.floor(num / 2)
    }
    while (!stack.isEmpty()) {
        result += stack.pop().toString()
    }
    return result
}
// console.log(decimalToBinary(10));
// console.log(decimalToBinary(100));
// console.log(decimalToBinary(23));

// 输入'))())()'
/**
 *  最长有效长括号
 * @param {*} s 
 */
function longString (s) {
    const stack = new Stack()
    let res = 0
    stack.push(-1) // 初始参照物
    for (let i = 0; i < s.length; i++) {
        let c = s.charAt(i) // charAt 获取指定位置的字符
        if (c === '(') {
            // 入栈
            stack.push(i)
        } else {
            // 遇到 ) 出栈
            stack.pop()
            if (stack.isEmpty()) {
                // 当栈为空的时候
                stack.push(i)
            } else {
                // 当栈不为空的时候
                res = Math.max(res, i - stack.peek()) // 确定最大的数字
            }
        }
    }
    return res
}
// console.log(longString(')()())'));

/**
 * 
 * @param {*} height [0,1,0,2,1,0,1,3,2,1,2,1]
 */
// 接雨水
function suluTion (height) {
    const stack = new Stack()
    // 将height的第一个元素入栈
    stack.push(height[0])
    
}